package interview.arraysandstrings;

import java.util.HashMap;

public class AllUniqueCharacter {
	public boolean isAllUniqueCharacters(String str) {
		char[] array = str.toCharArray();
		int[] alphabet = new int[256];

		for(int i = 0; i < alphabet.length; i++) {
			alphabet[i] = 0;
		}
		
		for(int i = 0; i < array.length; i++) {
			if(alphabet[array[i]] == 0) {
				alphabet[array[i]] = 1;
			} else {
				return false;
			}
		}

		return true;
	}

	public boolean isAllUniqueCharactersHashmap(String str) {
		char[] array = str.toCharArray();
		HashMap<Character, Integer> alphabet = new HashMap<Character, Integer>();
		Integer one = new Integer(1);
		for(int i = 0; i < array.length; i++) {
			if(alphabet.get(array[i]) == null) {
				alphabet.put(array[i], one);
			} else {
				return false;
			}
		}
		return true;
	}
}
